package com.itheima.reggie.common;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLNonTransientException;

@RestControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理指定异常：SQLNonTransientException
     */
    @ExceptionHandler(SQLNonTransientException.class)
    public R<String> handler1(SQLNonTransientException ex) {
        ex.printStackTrace();
        String message = ex.getMessage();
        return R.error(message.split(" ")[2]+"账号已存在");
    }
    @ExceptionHandler(CustomerException.class)
    public R<String> handler1(CustomerException ex) {
        ex.printStackTrace();
        return R.error(ex.getMessage());
    }
}